package uoc.biblioteca.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import uoc.biblioteca.mappings.dao.SolicitudLlibreHome;
import uoc.biblioteca.mappings.dao.SolicitudRevistaHome;
import uoc.biblioteca.mappings.object.UserVo;
import uoc.biblioteca.struts.form.GestionSolicitudForm;


public class GestionNovetatsAction extends BaseAction {
    
   
	private static final Log log = LogFactory.getLog(MisSolicitudsListAction.class);
	
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
    
				GestionSolicitudForm  gestionSolicitudForm = (GestionSolicitudForm ) form;
				
				
				try{
					 //Comprobar si la session esta guardada
					UserVo userLogin = obtenerUserSession(request);
					if(userLogin==null){
						request.getSession().setAttribute("ERROR","\n" +NO_USER_SESSION);
						return mapping.findForward("errorNotUser");
					}
					
					SolicitudLlibreHome llibreHome = new SolicitudLlibreHome();
					SolicitudRevistaHome revistaHome = new SolicitudRevistaHome();
					
					gestionSolicitudForm.setLlibres(llibreHome.getAllSolicitudsLlibreNoves());
					gestionSolicitudForm.setRevistes(revistaHome.getAllSolicitudsRevistaNoves());
					
					return mapping.findForward("gestioNovesList");
				}
				catch (Exception e) {
					e.printStackTrace();
					log.error("Error: ", e);
					request.getSession().setAttribute("ERROR","\n" +e.toString()  );
					return mapping.findForward("error");
				}
			
	}
}